package cn.cqie.frame.controller;


import cn.cqie.frame.bo.query.QueryCourseBo;
import cn.cqie.frame.entity.Course;
import cn.cqie.frame.service.CourseService;
import cn.cqie.frame.utils.MyPageHelper;
import cn.cqie.frame.vo.CourseVo;
import cn.cqie.frame.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-09
 */
@RestController
@Api("课程管理")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @ApiOperation("新增/更新课程信息")
    @PostMapping(value = "/course/saveOrUpdateCourse")
    public ResultVo<CourseVo> saveOrUpdateCourse(@Valid @RequestBody Course bo) {
        CourseVo courseVo = courseService.saveOrUpdateCourse(bo);
        return ResultVo.success(courseVo);
    }
    @ApiOperation("查询课程信息分页")
    @GetMapping(value = "/course/courseInfoPage")
    public ResultVo<PageInfo<CourseVo>> getPageList(QueryCourseBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(courseService.list(bo)));
    }
    @ApiOperation("删除课程")
    @DeleteMapping("/course/deleterCourse/{courseId}")
    public ResultVo<Void> deleterClass(@PathVariable Integer courseId) {
        Boolean aBoolean = courseService.deleterCourse(courseId);
        return aBoolean ? ResultVo.success() : ResultVo.error("删除失败");
    }
}

